﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebAPI10086.Controllers
{
    public class DbInitializeHelper
    {
        public static void Initilizer()
        {
            using (var db = new Admin10086DbContext())
            {
                db.Database.EnsureCreated();

                var tempBrand = db.Brands.Any();
                if (!tempBrand)
                {
                    var bran = new Brand
                    {
                        BrAndName = "Apple",
                        Description = "美国的一个品牌，相当大牛"
                    };

                    db.Brands.Add(bran);

                    db.SaveChanges();

                    db.Products.AddRange(new Product[]
                    {
                    new Product
                    {
                        ProductName = "Iphone X 红色",
                        ShortDesc = "这是一个简介描述",
                        FullDesc = "这是一个详情",
                        BrandId = bran.Id
                    },new Product
                    {
                        ProductName = "Iphone X 金色",
                        ShortDesc = "沙雕零简介描述",
                        FullDesc = "母鸡一个详情",
                        BrandId = bran.Id
                    }
                    });

                    db.SaveChanges();
                }
            }
                
        }
    }
}
